/**
 *******************************************************************************
 * @FileName  : bd_Addr.c
 * @Author    : GaoQiu
 * @CreateDate: 2020-05-18
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */
#include <string.h>
#include <stdio.h>
#include "bd_addr.h"


/**
 * @brief  : Copy bluetooch device address.
 * @param  : pTo       Pointer point to BD_ADDR buffer.
 * @param  : pFrom     Pointer point to BD_ADDR buffer.
 * @return : None.
 */
void BdaCpy(uint8_t *pDst, uint8_t *pSrc)
{
	memcpy(pDst, pSrc, BD_ADDR_LEN);
}

/**
 * @brief  : Compare bluetooch device address.
 * @param  : pDst1       Pointer point to BD_ADDR1
 * @param  : pDst2       Pointer point to BD_ADDR2
 * @return : TRUE if BD_ADDR1 == BD_ADDR2 or FALSE.
 */
bool_t BdaCmp(uint8_t* pAddr1, uint8_t *pAddr2)
{
	return (memcmp(pAddr1, pAddr2, BD_ADDR_LEN) == 0);
}

#if 0
int BdaToString(char *buf, int bufLen, uint8_t *bda)
{
	int cnt = 0;
	uint8_t ascii[] = "0123456789ABCDEF";

	for(int i=0; i<BD_ADDR_LEN; i++)
	{
		buf[cnt++] = ascii[(bda[BD_ADDR_LEN - i - 1] >> 4) & 0x0f];
		buf[cnt++] = ascii[(bda[BD_ADDR_LEN - i - 1] >> 0) & 0x0f];

		if(i < BD_ADDR_LEN-1){
			buf[cnt++] = ':';
		}

		if(cnt >= bufLen)
		{
			return cnt;
		}
	}

	return cnt;
}
#else
void BdaToString(char *str, uint32_t len, uint8_t addr[6], uint8_t type)
{
	snprintf(str, len, "%02X:%02X:%02X:%02X:%02X:%02X (%s)",
			addr[5], addr[4], addr[3], addr[2],
			addr[1], addr[0],
			type ==0 ? "public":"random");
}
#endif
